using System;
using SLS.ExClassLib.Events;
using SLS.ExClassLib.Message;
namespace LanSunStudio.Service.WorkFlowService
{ 
    partial class WorkFlowCenterService 
    {
        

        private bool HandleWFWiseJob(MessageEx msg, Guid UID)
        {
            string JobID = msg.JobID;
            return false;
        }
        private void RaiseEvent(MessageEx msg, Guid UID)
        {
            if (HandleWFWiseJob(msg, UID))
            {
                return;
            }
            string JobID = msg.JobID;
            switch (JobID)
            {
                 case "OnJobArrival":
                    RaiseJobArrivalEvent(msg, UID);
                    break;
                case "OnFinishEdit":
                    RaiseJobEditFinishEvent(msg, UID);
                    break;
                case "OnFinishQuery":
                    RaiseJobQueryFinishEvent(msg, UID);
                    break;
                case "OnStartNewJob":
                    RaiseChildWorkFlowStartEvent(msg, UID);
                    break;
                case "OnThisPass":
                    RaiseThisPassEvent(msg, UID);
                    break;
                case "OnThisFail":
                    RaiseThisFailEvent(msg, UID);
                    break;
                case "OnSelectedRecordEdit":
                    RaiseEditSelectedRecordEvent(msg, UID);
                    break;
                case "OnUpdateDone":
                    RaiseJobEditFinishEvent(msg, UID);
                    break;
                case "OnSingleEnd":
                    RaiseJobEditFinishEvent(msg, UID);
                    break;
                case "OnFileNewRecord":
                    RaiseFileNewRecordEvent(msg, UID);
                    break;
                case "OnRecordCopy":
                    RaiseFileCopyRecordEvent(msg, UID);
                    break;
                case "OnFileSaveRecord":
                    RaiseFileSaveRecordEvent(msg, UID);
                    break;
                case "OnValidateRecord":
                    RaiseValidateRecordEvent(msg, UID);
                    break;
                case "OnCreateByTemplate":
                    this.RaiseCreateByTemplateEvent(msg, UID);
                    break;
                case "OnCreateByQuery":
                    this.RaiseJobStartEvent(msg, UID);
                    break;
                case "OnCreateByQueryFinish":
                    this.RaiseJobQueryFinishEvent(msg, UID);
                    break;
                case "OnGetWorkflowActivies":
                    RaiseGetWorkflowActiviesEvent(msg, UID);
                    break;
                case "OnWriteLog":
                    RaiseWriteLogEvent(msg, UID);
                    break; 
                #region WFEditGoodsMaster
                case "OnJobStartEdit":
                    RaiseJobStartEditEvent(msg, UID);
                    break;
                case "OnStartChildWorkFlow":
                    RaiseReturnResultEvent(msg, UID);
                    break;
                case "OnSelectedRecordEvent":
                    RaiseEditSelectedRecordEvent(msg, UID);
                    break;
                #endregion

                default:
                    m_log.Warn("WorkFlowContract/HandleWFContractEvent unknown" + JobID);
                    break;

            }
        }
        public void RaiseEditGoodsTypeEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (EditRecord != null)
                    EditRecord(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseValidateRecordEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (ValidateRecord != null)
                    ValidateRecord(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseReturnResultEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (ReturnResult != null)
                    ReturnResult(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
        }
        public void RaiseThisPassEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (ThisPass != null)
                    ThisPass(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseThisFailEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (ThisFail != null)
                    ThisFail(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        //ThisPass  ThisFail
        public void RaiseJobStartEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (JobStarted != null)
                    JobStarted(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
        }
        public void RaiseJobEditFinishEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (JobEditFinish != null)
                    JobEditFinish(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public void RaiseJobQueryFinishEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (JobQueryFinish != null)
                    JobQueryFinish(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
        }
        public void RaiseJobStartEditEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (JobStartEdit != null)
                    JobStartEdit(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseEditSelectedRecordEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (EditSelectedRecord != null)
                    EditSelectedRecord(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseFileNewRecordEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (FileNewRecord != null)
                    FileNewRecord(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseFileCopyRecordEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (FileCopyRecord != null)
                    FileCopyRecord(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
        }
        public void RaiseFileSaveRecordEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (FileSaveRecord != null)
                    FileSaveRecord(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
        }

        public void RaiseCreateByTemplateEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (CreateByTemplate != null)
                    CreateByTemplate(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
        }
        public void RaiseWriteLogEvent(MessageEx msg, Guid UID)
        {

            try
            {
                if (WriteLog != null)
                    WriteLog(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        public void RaiseGetWorkflowActiviesEvent(MessageEx msg, Guid UID)
        {
            if (UID == Guid.Empty)
                return;
            try
            {
                if (GetWorkflowActivies != null)
                    GetWorkflowActivies(null, new ExMessageExEventArgs(UID, msg));
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        public void RaiseChildWorkFlowStartEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (ChildWorkFlowStart != null)
                {
                    ChildWorkFlowStart(null, new ExMessageExEventArgs(UID, msg));
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void RaiseJobArrivalEvent(MessageEx msg, Guid UID)
        {
            try
            {
                if (OnJobArrival != null)
                {
                    OnJobArrival(null, new ExMessageExEventArgs(UID, msg));
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 
    }
}
